package dao.Frame;


import java.awt.EventQueue;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.ImageIcon;

import java.awt.Color;

/**
 * @author 张新林
 * 时间 2015年3月21日下午5:07:26
 * 包名 dao.Frame
 * 类名 StartFrame
 * 游戏入口界面，显示游戏的总菜单
 * 界面流程：StartFrame -> SelectFrame -> MainFrame
 */
public class StartFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4292602402747023078L;
	private JPanel contentPane;
	private final JPanel panel = new JPanel();

//	private BufferedImage bi;
//	private Graphics g2;
	private int i=0;
	private JLabel label1;
	private JLabel label2;
	private JLabel label3;
	private JLabel label4;
	private JLabel label5;
	Image background;
	private JLabel partlabel;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StartFrame frame = new StartFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StartFrame() {
	    
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 598, 402);
		setTitle("英雄对决");
		background=Toolkit.getDefaultToolkit().getImage("image\\"+"back0.gif");
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		panel.setBounds(0, 0, 582, 364);
		contentPane.add(panel);
		panel.setLayout(null);
		
		label1 = new JLabel("剧情版");
		label1.setBackground(Color.GREEN);
		label1.setOpaque(true);
		label1.setFont(new Font("华文隶书", Font.PLAIN, 25));
		label1.setBounds(403, 179, 131, 26);
		label1.addMouseListener(new BtnMouseListener());
		panel.add(label1);
		
		label2 = new JLabel("单机对战版");
		label2.setBackground(Color.GREEN);
		label2.setFont(new Font("华文隶书", Font.PLAIN, 25));
		label2.setBounds(403, 204, 131, 26);
		label2.addMouseListener(new BtnMouseListener());
		panel.add(label2);
		
		label3 = new JLabel("网络对战版");
		label3.setBackground(Color.GREEN);
		label3.setFont(new Font("华文隶书", Font.PLAIN, 25));
		label3.setBounds(403, 227, 131, 26);
		label3.addMouseListener(new BtnMouseListener());
		panel.add(label3);
		
		label4 = new JLabel("帮助");
		label4.setBackground(Color.GREEN);
		label4.setFont(new Font("华文隶书", Font.PLAIN, 25));
		label4.setBounds(403, 252, 131, 26);
		label4.addMouseListener(new BtnMouseListener());
		panel.add(label4);
		
		label5 = new JLabel("离开游戏");
		label5.setBackground(Color.GREEN);
		label5.setFont(new Font("华文隶书", Font.PLAIN, 25));
		label5.setBounds(403, 278, 131, 26);
		label5.addMouseListener(new BtnMouseListener());
		panel.add(label5);
		
		JLabel publicJLabel = new JLabel("开发者@张新林");
		publicJLabel.setBackground(Color.GREEN);
		publicJLabel.setFont(new Font("", Font.PLAIN, 11));
		publicJLabel.setBounds(233, 342, 131, 26);
		panel.add(publicJLabel);
		
		JLabel title_label = new JLabel("英雄对决");
		title_label.setFont(new Font("隶书", Font.PLAIN, 38));
		title_label.setBounds(204, 33, 189, 38);
		panel.add(title_label);
		
		partlabel = new JLabel("");
		partlabel.setIcon(new ImageIcon("image/part.png"));
		partlabel.setBounds(91, 81, 326, 287);
		panel.add(partlabel);
		
		JLabel background_label = new JLabel("");
		background_label.setFont(new Font("方正姚体", Font.PLAIN, 28));
		//lblNewLabel_1.setBackground(Color.WHITE);
		background_label.setIcon(new ImageIcon("image/back0.gif"));
		background_label.setBounds(0, 0, 582, 364);
		panel.add(background_label);

		//监听键盘上下移动，每次up或down都改变菜单选中的位置
		this.addKeyListener(new KeyAdapter()
		{
			public void keyPressed(KeyEvent e)
			{
				//JOptionPane.showMessageDialog(null, "22");
				if(e.getKeyCode()==KeyEvent.VK_UP)
				{
					i--;
					if(i<0)
						i=4;
					Changemenu(i);
				}
				if(e.getKeyCode()==KeyEvent.VK_DOWN)
				{
					i++;
					if(i>4)
						i=0;
					Changemenu(i);
				}
			}
		});
		
		setLocationRelativeTo(null);//设置居中
	}
	
	public void Changemenu(int i)
	{
		if(i==0)
		{
			label1.setOpaque(true);
			label2.setOpaque(false);
			label3.setOpaque(false);
			label4.setOpaque(false);
			label5.setOpaque(false);
		}else if(i==1){
			label1.setOpaque(false);
			label2.setOpaque(true);
			label3.setOpaque(false);
			label4.setOpaque(false);
			label5.setOpaque(false);
		}else if(i==2){
			label1.setOpaque(false);
			label2.setOpaque(false);
			label3.setOpaque(true);
			label4.setOpaque(false);
			label5.setOpaque(false);
		}else if(i==3){
			label1.setOpaque(false);
			label2.setOpaque(false);
			label3.setOpaque(false);
			label4.setOpaque(true);
			label5.setOpaque(false);
		}else if(i==4){
			label1.setOpaque(false);
			label2.setOpaque(false);
			label3.setOpaque(false);
			label4.setOpaque(false);
			label5.setOpaque(true);
		}
	}
	
	// 内部类ColorEventListener，实现ActionListener接口
	  class BtnMouseListener implements MouseListener{

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
		 * 鼠标点击效果
		 */
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			if (e.getSource() == label1) {
				JOptionPane.showMessageDialog(null,"剧情版敬请期待，感谢您的支持");
			}else if(e.getSource() == label2){
				SelectFrame selectFrame=new SelectFrame();
				selectFrame.setVisible(true);
				dispose();
			}else if(e.getSource() == label3){
				JOptionPane.showMessageDialog(null,"本模块还没被开发，感谢您的支持");
			}else if(e.getSource() == label4){
				HelpFrame helpFrame=new HelpFrame();
				helpFrame.setVisible(true);
			}else if(e.getSource() == label5){
				JOptionPane.showMessageDialog(null,"游戏结束，感谢您的使用");
				dispose();
			}
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
		 */
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
		 */
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
		 * 监听鼠标事情，当鼠标移入选中的菜单中，改变菜单背景色，造成动画效果
		 */
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if (e.getSource() == label1) {
				label1.setOpaque(true);
				label2.setOpaque(false);
				label3.setOpaque(false);
				label4.setOpaque(false);
				label5.setOpaque(false);
			}else if(e.getSource() == label2){
				label1.setOpaque(false);
				label2.setOpaque(true);
				label3.setOpaque(false);
				label4.setOpaque(false);
				label5.setOpaque(false);
			}else if(e.getSource() == label3){
				label1.setOpaque(false);
				label2.setOpaque(false);
				label3.setOpaque(true);
				label4.setOpaque(false);
				label5.setOpaque(false);
			}else if(e.getSource() == label4){
				label1.setOpaque(false);
				label2.setOpaque(false);
				label3.setOpaque(false);
				label4.setOpaque(true);
				label5.setOpaque(false);
			}else if(e.getSource() == label5){
				label1.setOpaque(false);
				label2.setOpaque(false);
				label3.setOpaque(false);
				label4.setOpaque(false);
				label5.setOpaque(true);
			}
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
		 */
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

	  }
	  

}
